Code Mandelbrot

De Mandelbrot set

terug

size(520,380);
background(0);
translate(width/2,height/2);   
int[] COL =
{#000000,#0000AA,#00AA00,#00AAAA,#AA0000,#AA00AA,#AA5500,#AAAAAA,#555555,
#5555FF,#55FF55,#55FFFF,#FF5555,#FF55FF,#FFFF55,#FFFFFF};
float S,X,Y,Z,DELH=1.6,DELV=1.34,AC=-.65;
int C,L,N1=260,N2=int
(N1*DELV/DELH);
for(int i=-N1;i<=N1;i++){
float A=AC+i*DELH/N1;
for(int j=0;j<=N2;j++){
float B=j*DELV/N2;

float U=4*(sq(A)+sq(B));
float V=U-2*A+.25;
if ((U+8*A+3.75>=0)&&(V-sqrt(V)+2*A-.5>=0)){

X=A;Y=B;C=0;
for (int k=0;k<50;k++){
Z=X;C=C+1;
X=sq(X)-sq(Y)+A;
Y=2*Z*Y+B;

S=sq(X)+sq(Y);
if(S>100){k=50;}  //exit for
}
if(C<40){L=1+C%8;}
else{L=0;}
stroke
(COL[L]);
point(i,j);
point(i,-j);
}
}
}

Details van de Mandelbot set

terug

int[] COL =
{#000000,#0000AA,#00AA00,#00AAAA,#AA0000,#AA00AA,#AA5500,#AAAAAA,#555555,
#5555FF,#55FF55,#55FFFF,#FF5555,#FF55FF,#FFFF55,#FFFFFF};
float S,X,Y,Z,AC=-1.927199,BC=0,DEL=.0005;
int 
k,L,m,N1=320,N2=int(N1*.75),KMAX=200;
void setup(){
size(400,400);
background(0);
noLoop();
}
void draw(){
translate(width/2,height/2);   
for(int i=-N1;i<=N1;i++){
float A=AC+i*DEL/N1;
for(int j=-N2;j<=N2;j++){
float 
B=BC+j*.75*DEL/N2;
X=A;Y=B;k=0;
for (int m=0;m<KMAX;m++){
Z=X;
X=sq(X)-sq(Y)+A;

Y=2*Z*Y+B;
S=sq(X)+sq(Y);k=k+1;
if(S>100){m=KMAX;}  //exit for
}
if(k<KMAX)
{L=8+k%8;}
else{L=0;}
stroke(COL[L]);
point(i,j);
}
}
}
void mousePressed(){
m=m+1;
int rem=int
(m%15);
switch(rem) {
case 0:
AC=-1.953712;BC=0;DEL=.000049;KMAX=200; 
break;
case 1:

AC=-.698;BC=0.3785;DEL=.004;KMAX=100; 
break;
case 2:
AC=-
1.28408;BC=0.42726;DEL=.000625;KMAX=100; 
break;
case 3:
AC=-
1.25636;BC=0.38032;DEL=.02;KMAX=100; 
break;
case 4:
AC=-.91667;BC=.26667;DEL=.06;KMAX=200; 

break;
case 5:
AC=-.7769;BC=.1334;DEL=.0032;KMAX=150; 
break;
case 6:

AC=-.7777;BC=.1355;DEL=.0037;KMAX=150; 
break;
case 7:

AC=-.1011;BC=.9563;DEL=.0016;KMAX=300;
break;
case 8:
AC=-.7392;BC=.1745;DEL=.0028;KMAX=200; 
break;
case 9:
AC=-.023262;BC=.999253;DEL=.003;KMAX=100; 
break;
case 10:
AC=-
1.927199;BC=0;DEL=.0005;KMAX=200; 
break;
case 11:
AC=-.01556;BC=1.02071;DEL=.0015;KMAX=100; 
break;
case 12:
AC=.304;BC=.028;DEL=.0028;KMAX=200; 
break;
case 13:

AC=.2812;BC=.00948;DEL=.00005;KMAX=300; 
break;
case 14:

AC=.2833;BC=.0107;DEL=.002;KMAX=200; 
break;
default:
AC=-.65;BC=0;DEL=1.6;KMAX=100;
break;
}

background(0);
redraw();

De Mandelbrot set van een sinus functie

terug

/*from H.A. Lauwerier Graphics&Fractals, 1994 program MANDELX2 translated into
Processing by J.G.van Unnik, 
2011*/
size(480,360);
translate(width/2,height/2);
int[] COL = {#000000,#0000AA,#00AA00,#00AAAA,#AA0000,#AA00AA, #AA5500,#AAAAAA,
#555555, #5555FF,#55FF55,#55FFFF,#FF5555,#FF55FF,#FFFF55,#FFFFFF};
float DELH=.8,DELV=.8,X,Y;
int N1=200,N2=int
(N1*DELV/DELH),L=0;
boolean none=false;
for(int i=0;i<=N1;i++){
float a=DELH*i/N1;
for (int j=0;j<=N2;j++){

float b=j*DELV/N2;
X=1;Y=0;
for(int k=1;k<101;k++){
float s=sq(X)+sq(Y),s2=sq(s)+.00000001;
if
(s>64){L=1+k%14;
k=101;}
float x2=sq(X)-sq(Y),y2=2*X*Y;
float xr=x2/s2,yr=-y2/s2;
float 
x1=x2+xr,y1=y2+yr;
X=a*x1-b*y1;Y=a*y1+b*x1;
if(k==100){none=true;}     
}
if(none){L=9;

none=false;}
stroke(COL[L]);
point(i,j);point(i,-j);
point(-i,-j);point(-i,j);
}
}

De mandelbrot set van x^4

terug

/*from H.A. Lauwerier Graphics&Fractals, 1994 program MANDELX3 translated into
Processing by J.G.van Unnik, 
2011*/
size(480,360);
translate(width/2,height/2);
int[] COL ={#000000,#0000AA, #5555FF, #AA0000, #FF5555, 
#00AA00, #55FF55,#FFFF55,#AA5500};
float DELH=PI,DELV=.75*PI,X,Y;
int N1=240,N2=int
(N1*DELV/DELH),L=0;
boolean none=false;
for(int i=0;i<=N1;i++){
for (int j=0;j<=N2;j++){
float 
a=DELH*i/N1,b=DELV*j/N2;
X=PI/2;Y=0;
for(int k=1;k<65;k++){
if (abs(Y)>12){L=1+k%8;

k=65;}  //exit for
float u=exp(Y),v=1/u,ch=(u+v)/2,sh=(u-v)/2;
float ss=sin(X),cs=cos(X);
float x1=a
+PI*ss*ch, y1=b+PI*cs*sh;
float dist=abs(X-x1)+abs(Y-y1);
if(dist<.001){L=0;
k=65;}

X=x1;Y=y1;
if(k==64){none=true;}
}
if(none){L=0;
none=false;}
stroke(COL[L]);
point(i,j);point
(i,-j);
point(-i,-j);point(-i,j);
}
}

terug